<template>
  <div>
    <el-row style="position:inherit">
      <el-col :span="9" class="propertyborder-title">
        <a-tooltip>
          <template slot="title"> 设置显示字段</template>
          显示字段
        </a-tooltip>
      </el-col>
      <el-col :span="15" class="propertyborder-content">
        <el-select v-model="bindname" placeholder="请选择" @focus="openwhereconfig" @change="changeselect">
          <el-option v-for="item in selectfiledList" :key="item.bindname" :label="item.headname" :value="item.bindname">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { getApiConfigByCallMethodCode } from '@/api/packageInterface.js'
export default {
  props: ['contdata', 'sourceApi'],
  data () {
    return { selectfiledList: [], bindname: '', headname: '', oldsourceApi: '' }
  },
  methods: {
    openwhereconfig () {
      if (this.sourceApi !== '') {
        getApiConfigByCallMethodCode(this.sourceApi).then(res => {
          if (res.code === 0) {
            this.selectfiledList = JSON.parse(res.data.headList)
          }
        })
      } else {
        this.selectfiledList = []
      }
    },
    changeselect () {
      this.contdata.options.filedList.bindname = this.bindname
      this.contdata.options.filedList.headname = this.headname
    }
  },
  created () {
    this.bindname = this.contdata.options.filedList.bindname
    this.headname = this.contdata.options.filedList.headname
  },
  watch: {
    contdata (val) {
      this.bindname = val.options.filedList.bindname
      this.headname = val.options.filedList.headname
    }
  }
}
</script>
